using System.Runtime.InteropServices;
using System.Web;
using Microsoft.SharePoint;

namespace Redirection.Features.Redirection_Site
{
    /// <summary>
    ///     This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    ///     The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>
    [Guid("aeb20541-1bd4-4d42-80a8-a0add3c70480")]
    public class Redirection_SiteEventReceiver : SPFeatureReceiver
    {
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            var web = properties.Feature.Parent as SPWeb;
            if (web == null) return;

            var lists = web.Lists.TryGetList(ConstantsService.Lists.RedirectionsList);
            if (lists == null) return;
            lists.Delete();

            var cacheService = new CacheService(web.Site, HttpContext.Current);
            cacheService.ClearCache();
        }
    }
}